1457D - XOR-gun - CodeForces Solution


brute force constructive algorithms dp *2000

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define ar array
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()

const int MAX_N = 2e5 + 5;
const ll MOD =  998244353;
const ll INF = 1e9;
const ld EPS = 1e-9;

ll inv(ll a) {
  return a <= 1 ? a : MOD - (long long)(MOD/a) * inv(MOD % a) % MOD;
}

void solve()
{
    ll n;cin>>n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++)
    cin>>a[i];
    if(n>=100)
    {
        cout << "1\n";
        return;
    }
    ll ans = 1e9;
    for(ll i=0;i<n;i++)
    {
        ll t1=0,t2=0;
        for(ll j=i+1;j<n;j++)
        {
            t1^=a[j];
            t2=0;
            for(ll k=i;k>=0;k--)
            {
                t2^=a[k];
                if(t2>t1)
                {
                    ans=min(ans,j-k-1);
                }
            }
        }
    }

    if(ans==1e9)
    cout << -1 << "\n";
    else
    cout << ans << "\n";

    return; 
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc=1 ;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
                //    cout << "Case #" << t << ": ";
        solve();
    }
}


Comments

Submit
0 Comments
More Questions

236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words
160A - Twins
1A - Theatre Square
1614B - Divan and a New Project
791A - Bear and Big Brother
1452A - Robot Program
344A - Magnets
96A - Football
702B - Powers of Two
1036A - Function Height
443A - Anton and Letters
1478B - Nezzar and Lucky Number
228A - Is your horseshoe on the other hoof
122A - Lucky Division
1611C - Polycarp Recovers the Permutation
432A - Choosing Teams
758A - Holiday Of Equality
1650C - Weight of the System of Nested Segments
1097A - Gennady and a Card Game
248A - Cupboards
1641A - Great Sequence
1537A - Arithmetic Array
1370A - Maximum GCD